<?php
namespace app\index\controller;
// use app\index\
class Photo extends Base
{
    public function index()
    {      
        $id=request()->param('id');   
        $viewPage=$this->getIndexPage($id);    
        $photo=db("cms_photo");
        $channel=db("channel");
                
        $pid=$channel->where("id=".$id)->value("pid");
        if($pid > 0){
            $gcid=$pid;
            $pcid=$id;
            $where['cid']=$id;
            $lchannel=$this->get_left_channel($pid);
            $fname=$channel->where("id",$pid)->value("name");
            $pnavName=$channel->where("id=".$pcid)->value("name");
        }else{
            $gcid=$id;
            // $pcid=$channel->where("pid=".$id)->value("id");
            $cid_arr=db("channel")->where("pid=".$gcid)->column("id");
            $where['cid']=array("in",$cid_arr);
            $lchannel=$this->get_left_channel($id);
            $fname=$channel->where("id",$id)->value("name");
            $pnavName=$channel->where("id=".$gcid)->value("name");
        }
        $where['status']=1;
        
        $mess=$photo->where($where)->order("sort asc , id DESC")->select();
        for ($i=0; $i < count($mess); $i++) { 
            if($mess[$i]['thumb']){
                $mess[$i]['annexes']=db("filex")->where("id=".$mess[$i]['thumb'])->value("thumb");  
            }
            $mess[$i]['content']=html_entity_decode($mess[$i]['content']);
        }
        $gnavName=$channel->where("id=".$gcid)->value("name");        

        // SEO META关键字配置
        $meta=$this->meta;
        $meta['title']=$pnavName.' '.$gnavName.' '.$meta['title'];

        $meta['keywords']=$pnavName.$gnavName.$meta['keywords'];

        $meta['descript']=$pnavName.$gnavName.$meta['descript'];

        $this->assign("meta",$meta);
        $modelx=$channel->where("id",$gcid)->value("modelx");
        $modelxMark=db("modelx")->where("id=".$modelx)->value("mark");
        $this->assign("modelxMark",$modelxMark);

        $banner=$this->get_banner($gcid);
        $this->assign("banner",$banner);
        $this->assign("pnavName",$pnavName);
        $this->assign("gnavName",$gnavName);
        $this->assign("lchannel",$lchannel);
        $this->assign("cid",$cid);
        $this->assign("gcid",$gcid);
        $this->assign("pcid",$pcid);
        $this->assign("fname",$fname);
        $this->assign("mess",$mess);
        return view($viewPage);
    }  
    public function detail()
    {
        $id=request()->param('id');       
        $photo=db("cms_photo");
        $channel=db("channel");

        $where['id']=$id;
        $mess=$photo->where($where)->find();
        // html_entity_decode 把HTML 实体转换回字符
        // htmlentities 把字符转换为 HTML 实体
        // htmlspecialchars 把预定义的字符转换为 HTML 实体
        $mess['content']=html_entity_decode($mess['content']);
        if($mess['thumb']){
            $mess['annexes']=db("filex")->where("id=".$mess['thumb'])->value('thumb');
        }
        if($mess['images']){

            $where['id']=array("in",explode(",", $mess['images']));
            // print_r($where);exit;
            $mess['photos']=db("filex")->where($where)->select();
        }
        $pcid=$mess['cid'];
        $viewPage=$this->getDetailPage($pcid);
        
        $gcid=$channel->where("id=".$pcid)->value("pid");
        
        // $where['status']=1;
        
        $fname=$channel->where("id",$gcid)->value("name");
        $lchannel=$this->get_left_channel($gcid);
        $gnavName=$channel->where("id=".$gcid)->value("name");
        $pnavName=$channel->where("id=".$pcid)->value("name");

        // SEO META关键字配置
        $meta=$this->meta;
        $meta['title']=$mess['title'].' '.$pnavName.' '.$gnavName.' '.$meta['title'];
        if($mess['keywords']){
            $meta['keywords']=$mess['keywords'];
        }else{
            $meta['keywords']=$mess['title'].$pnavName.$gnavName.$meta['keywords'];
        }
        if($mess['descript']){
            $meta['descript']=$mess['descript'];
        }else{
            $meta['descript']=$mess['title'].$pnavName.$gnavName.$meta['descript'];
        }
        $this->assign("meta",$meta);

        $modelx=$channel->where("id",$gcid)->value("modelx");
        $modelxMark=db("modelx")->where("id=".$modelx)->value("mark");
        $this->assign("modelxMark",$modelxMark);
        $banner=$this->get_banner($gcid);
        $this->assign("banner",$banner);
        $this->assign("pnavName",$pnavName);
        $this->assign("gnavName",$gnavName);
        $this->assign("lchannel",$lchannel);
        $this->assign("pcid",$pcid);
        $this->assign("gcid",$gcid);
        $this->assign("fname",$fname);
        $this->assign("mess",$mess);
        return view($viewPage);
    }  
}
